﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Xml.Serialization;
using System.IO;

namespace Zove.Desktop.Tools {
    public partial class TaskView : DockContent {
        [Serializable]
        public class Task {
            public object Status {
                get;
                set;
            }

            public object Description {
                get;
                set;
            }
        }

        [Serializable]
        public class TaskList : List<Task> {
        }


        public TaskList Tasks {
            get;
            set;
        }

        public TaskView() {
            InitializeComponent();

            Tasks = new TaskList();
            this.Load += new EventHandler(TaskView_Load);
            this.FormClosing += new FormClosingEventHandler(TaskView_FormClosing);
        }

        private void TaskView_Load(object sender, EventArgs e) {
            if (!File.Exists(@"C:\tasks.xml")) {
                return;
            }

            XmlSerializer deserializer = new XmlSerializer(typeof(TaskList));
            TextReader textReader = new StreamReader(@"C:\tasks.xml");
            Tasks = (TaskList)deserializer.Deserialize(textReader);
            textReader.Close();

            this.dataGridView1.DataSource = Tasks;
        }

        public void TaskView_FormClosing(object sender, EventArgs e) {
            // store the tasks back to XML form
            XmlSerializer serializer = new XmlSerializer(typeof(TaskList));
            TextWriter textWriter = new StreamWriter(@"C:\tasks.xml");
            serializer.Serialize(textWriter, Tasks);
            textWriter.Close();
        }
    }
}
